﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：QS_LH_XIAOBIAOSBXX实体层次
//********************************************************************************//
#region Entity
namespace Entity
{
    using System;
    using System.Xml;
    [Serializable()]
    public class QS_LH_XIAOBIAOSBXX
    {

        private decimal m_dec_id;
        /// <summary>
        /// 主键
        /// </summary>
        public decimal ID { get { return m_dec_id; } set { m_dec_id = value; } }

        private string m_str_s_laihanbh;
        /// <summary>
        /// 来函编号
        /// </summary>
        public string S_LAIHANBH { get { return m_str_s_laihanbh; } set { m_str_s_laihanbh = value; } }

        private string m_str_s_shuibiaobh;
        /// <summary>
        /// 水表号
        /// </summary>
        public string S_SHUIBIAOBH { get { return m_str_s_shuibiaobh; } set { m_str_s_shuibiaobh = value; } }

        private string m_str_s_yonghuh;
        /// <summary>
        /// 用户号
        /// </summary>
        public string S_YONGHUH { get { return m_str_s_yonghuh; } set { m_str_s_yonghuh = value; } }
        public QS_LH_XIAOBIAOSBXX()
        {
        }
    }
}
#endregion
#region EntityProcess
namespace BLL.Access
{
    using System;
    using System.Data;
    //using System.Data.OracleClient;
    using Entity;
    using System.Configuration;
    using System.Data.Common;
    using Platform.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    using Oracle.DataAccess;
    public class QS_LH_XIAOBIAOSBXXProcess
    {
        #region Field
        protected string conn;
        #endregion
        #region Construction
        public QS_LH_XIAOBIAOSBXXProcess() { conn = Platform.Configuration.ConfigHelper.PlatformConnString; }
        #endregion
        #region public

        /// <summary>
        /// 根据QS_LH_XIAOBIAOSBXX实体添加或者修改QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        public bool InsertOrUpdate(QS_LH_XIAOBIAOSBXX QS_LH_XIAOBIAOSBXX, OracleTransaction Transaction)
        {
            if (QS_LH_XIAOBIAOSBXX.ID == 0)
            {
                InsertQS_LH_XIAOBIAOSBXX(QS_LH_XIAOBIAOSBXX, Transaction);
            }
            else
            {
                UpdateQS_LH_XIAOBIAOSBXX(QS_LH_XIAOBIAOSBXX, Transaction);
            }
            return QS_LH_XIAOBIAOSBXX.ID == 0 ? false : true;
        }

        /// <summary>
        /// 根据QS_LH_XIAOBIAOSBXX实体添加或修改QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        public bool InsertOrUpdate(QS_LH_XIAOBIAOSBXX QS_LH_XIAOBIAOSBXX)
        {
            return InsertOrUpdate(QS_LH_XIAOBIAOSBXX, null);
        }



        /// <summary>
        /// 根据QS_LH_XIAOBIAOSBXX主键删除QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_LH_XIAOBIAOSBXX(decimal ID, OracleTransaction Transaction)
        {
            string spName = "CS_DelQS_LH_XIAOBIAOSBXX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        /// 根据QS_LH_XIAOBIAOSBXX主键删除QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_LH_XIAOBIAOSBXX(decimal ID)
        {
            return DeleteQS_LH_XIAOBIAOSBXX(ID, null);
        }

        /// <summary>
        /// 根据条件删除QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_LH_XIAOBIAOSBXXesDynamic(string WhereClause, OracleTransaction Transaction)
        {
            string spName = "CS_DelQS_LH_XIAOBIAOSBXXesDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        /// 根据条件删除QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_LH_XIAOBIAOSBXXesDynamic(string WhereClause)
        {
            return DeleteQS_LH_XIAOBIAOSBXXesDynamic(WhereClause, null);
        }

        /// <summary>
        /// 根据QS_LH_XIAOBIAOSBXX主键选择QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_XIAOBIAOSBXX信息</returns>
        public QS_LH_XIAOBIAOSBXX SelectQS_LH_XIAOBIAOSBXX(decimal ID, OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_LH_XIAOBIAOSBXX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                QS_LH_XIAOBIAOSBXX QS_LH_XIAOBIAOSBXX = PopulateQS_LH_XIAOBIAOSBXX(rd);
                rd.Close();
                return QS_LH_XIAOBIAOSBXX;
            }
            else
                return null;
        }

        /// <summary>
        /// 根据QS_LH_XIAOBIAOSBXX主键选择QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <returns>QS_LH_XIAOBIAOSBXX信息</returns>
        public QS_LH_XIAOBIAOSBXX SelectQS_LH_XIAOBIAOSBXX(decimal ID)
        {
            return SelectQS_LH_XIAOBIAOSBXX(ID, null);
        }

        /// <summary>
        /// 选择所有QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有QS_LH_XIAOBIAOSBXX信息</returns>
        public DataTable SelectQS_LH_XIAOBIAOSBXXesAll(OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_LH_XIAOBIAOSBXXesAll";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }

        /// <summary>
        /// 选择所有QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <returns>所有QS_LH_XIAOBIAOSBXX信息</returns>
        public DataTable SelectQS_LH_XIAOBIAOSBXXesAll()
        {
            return SelectQS_LH_XIAOBIAOSBXXesAll(null);
        }

        /// <summary>
        /// 根据条件选择QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_XIAOBIAOSBXX信息</returns>
        public DataTable SelectQS_LH_XIAOBIAOSBXXesDynamic(string WhereClause, string OrderByExpression, OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_LH_XIAOBIAOSBXXesDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }


        /// <summary>
        /// 根据条件选择QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>QS_LH_XIAOBIAOSBXX信息</returns>
        public DataTable SelectQS_LH_XIAOBIAOSBXXesDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectQS_LH_XIAOBIAOSBXXesDynamic(WhereClause, OrderByExpression, null);
        }



        /// <summary>
        /// 根据条件选择QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_LH_XIAOBIAOSBXX信息</returns>
        public DataTable SelectQS_LH_XIAOBIAOSBXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize, OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_LH_XIAOBIAOSBXXesDynPaged";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }


        /// <summary>
        /// 根据条件选择QS_LH_XIAOBIAOSBXX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>QS_LH_XIAOBIAOSBXX信息</returns>
        public DataTable SelectQS_LH_XIAOBIAOSBXXesDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize)
        {
            return SelectQS_LH_XIAOBIAOSBXXesDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///根据条件更新QS_LH_XIAOBIAOSBXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_LH_XIAOBIAOSBXXesDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            int result = 0;
            if (UpdateValue == "" || WhereClause == "")
            {
                return 0;
            }
            string spName = "CS_UpdQS_LH_XIAOBIAOSBXXDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///根据条件更新QS_LH_XIAOBIAOSBXX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_LH_XIAOBIAOSBXXesDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateQS_LH_XIAOBIAOSBXXesDynamic(UpdateValue, WhereClause, null);
        }


        #endregion
        #region Private

        private int InsertQS_LH_XIAOBIAOSBXX(QS_LH_XIAOBIAOSBXX QS_LH_XIAOBIAOSBXX, OracleTransaction Transaction)
        {
            string spName = "CS_InsQS_LH_XIAOBIAOSBXX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_LH_XIAOBIAOSBXX.S_LAIHANBH;
            storedParams[1].Value = QS_LH_XIAOBIAOSBXX.S_SHUIBIAOBH;
            storedParams[2].Value = QS_LH_XIAOBIAOSBXX.S_YONGHUH;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            QS_LH_XIAOBIAOSBXX.ID = Convert.ToInt32(storedParams[3].Value);
            return result;
        }
        private bool UpdateQS_LH_XIAOBIAOSBXX(QS_LH_XIAOBIAOSBXX QS_LH_XIAOBIAOSBXX, OracleTransaction Transaction)
        {
            string spName = "CS_UpdQS_LH_XIAOBIAOSBXX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_LH_XIAOBIAOSBXX.S_LAIHANBH;
            storedParams[1].Value = QS_LH_XIAOBIAOSBXX.S_SHUIBIAOBH;
            storedParams[2].Value = QS_LH_XIAOBIAOSBXX.S_YONGHUH;
            storedParams[3].Value = QS_LH_XIAOBIAOSBXX.ID;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private QS_LH_XIAOBIAOSBXX PopulateQS_LH_XIAOBIAOSBXX(IDataReader dr)
        {
            QS_LH_XIAOBIAOSBXX QS_LH_XIAOBIAOSBXX = new QS_LH_XIAOBIAOSBXX();
            QS_LH_XIAOBIAOSBXX.ID = dr["ID"] == DBNull.Value ? (decimal)0 : (decimal)dr["ID"];
            QS_LH_XIAOBIAOSBXX.S_LAIHANBH = dr["S_LAIHANBH"] == DBNull.Value ? null : (string)dr["S_LAIHANBH"];
            QS_LH_XIAOBIAOSBXX.S_SHUIBIAOBH = dr["S_SHUIBIAOBH"] == DBNull.Value ? null : (string)dr["S_SHUIBIAOBH"];
            QS_LH_XIAOBIAOSBXX.S_YONGHUH = dr["S_YONGHUH"] == DBNull.Value ? null : (string)dr["S_YONGHUH"];
            return QS_LH_XIAOBIAOSBXX;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
            }
        }
        #endregion
    }
}
#endregion